package com.example.model;
import java.util.*;
import java.sql.*;
public class Authentication{
private String role;
public boolean authenticate(String user, String passwd)
{ 
boolean login=false;
try{
    
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     Connection con=DriverManager.getConnection("jdbc:mysql://localhost/emprecord", "root", "");
     Statement st=con.createStatement();
     
     String sqry = "select username,password from login where username='"+user+"'and password='"+passwd+"'";
     ResultSet rs=st.executeQuery(sqry);
     if(rs.next())
         { 
            login=true;
          }
    else{ 
         login=false;
         
     	}
	rs.close();
	st.close();
	con.close();
}catch(Exception e1)
	{System.out.println("Error:"+e1.getMessage()); 
	}
return login;
}
public String chkrole(String unam)
{
Authentication at=new Authentication();
try{
    
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     Connection con=DriverManager.getConnection("jdbc:mysql://localhost/emprecord", "root", "");
     Statement st=con.createStatement();
     
     String sqry = "select role from emplist where email_id='"+unam+"'";
     ResultSet rs=st.executeQuery(sqry);
	 while(rs.next())
         { 
			
		     //at.setRole(rs.getString(1));
			 role=rs.getString(1);
		}
		rs.close();
		st.close();
		con.close();
			 
}catch(Exception e1)
	{System.out.println("Error:"+e1.getMessage()); 
	}
	//return at.getRole();
	return role;
	
}

	public String getRole() {
		return role;
	}
	public void setRole(String role) {
		this.role = role;
	}
}